#include "scanner.h"
#include "parser.h"
#include <fstream.h>
#include <iostream.h>
#include <assert.h>

/*char *szToken[] = {
	"NONE",
	"PROGRAM_NUMBER",
	"ADDRESS",
	"UINT",
	"NINT",
	"UFLOAT",
	"NFLOAT",
	"COMMENT",
	"BLOCK_DELETE",
	"WHITE_SPACE",
	"TX_CODE",
	"EOB",
	"EOL",
	"EOF"
};*/

int main()
{
	ifstream ifs("c-rod.nc");
	Scanner scanner;
	Parser parser;
	ProgramComponentID programComponent;
	Block block;

	scanner.setInputStream(&ifs);
	parser.setScanner(&scanner);
	do {
		programComponent = parser.getProgramComponent();
		switch (programComponent) {
		case PROGRAM_START:
			cout << "%" << endl;
			break;
		case PROGRAM_LEADER:
			cout << parser.getLeader() << endl;
			break;
		case PROGRAM_NUMBER:
			cout << 'O' << parser.getProgramNumber() << endl;
			break;
		case PROGRAM_BLOCK:
			block = parser.getBlock();
			cout << "Block: ";
			switch (block.getID()) {
			case BLOCK_NONE:
				cout << "None" << endl;
				break;
			case BLOCK_EMPTY:
				cout << "Empty" << endl;
				break;
			case BLOCK_SKIPPED:
				cout << "Skipped" << endl;
				break;
			case BLOCK_STANDARD:
				cout << "Standard" << endl;
				break;
			case BLOCK_ERROR:
				cout << "Error" << endl;
				break;
			}
			break;
		case PROGRAM_END:
			cout << "%" << endl;
			return 0;
		case PROGRAM_ERROR:
			cout << "Error" << endl;
			return 0;
		}
	} while (programComponent != PROGRAM_END
		|| programComponent != PROGRAM_ERROR);
/*	while ("there is no EOF") {
		token = scanner.getToken();
		cout << szToken[token.getID()] << ' ';
		switch (token.getID()) {
		case TOKEN_NONE:
			cout << "Error! This should never happen! "
				"Check line " << scanner.getRow() << '.' << endl;
			return 0;
		case TOKEN_PROGRAM_NUMBER:
		case TOKEN_ADDRESS:
		case TOKEN_BLOCK_DELETE:
		case TOKEN_WHITE_SPACE:
		case TOKEN_TX_CODE:
		case TOKEN_EOB:
			cout << '(' << (char)token.getValue() << ')' << endl;
			break;
		case TOKEN_EOL:
			cout << endl;
			break;
		case TOKEN_UINT:
		case TOKEN_NINT:
		case TOKEN_UFLOAT:
		case TOKEN_NFLOAT:
			cout << endl;
			break;
		case TOKEN_COMMENT:
			cout << '(' << scanner.getLastLexeme()  << ')' << endl;
			break;
		case TOKEN_EOF:
			return 0;
		}
	}*/
	return 0;
}
